var app = getApp(),
  a = app.requirejs('core');
var loading = false;
Page({
  data: {
    show: false,
    status: -1,
    list: [],
    loaded: false,
    page: 1,
    hidden:-1
  },
  onLoad: function (t) {
    a.ReName(t.title);
    this.getlist();
  },
  getlist: function () {
    if (loading) {
      return;
    }
    loading = true;
    var that = this,
      page = that.data.page;
    a.get('Distribe/shareOrder', {
      page:page,
      uid: app.getCache('userinfo').uid,
      status: that.data.status
    }, function (t) {
      console.log(t)
      loading = false;
      if (t.code == 0) {
        if (typeof t.info == 'object'){
          var arr = []
          for (let i in t.info) {
            arr.push(t.info[i]);
          }
        }else{
          arr = t.info
        }
        
        that.setData({
          list: that.data.list.concat(arr),
          page: arr.length == 0 ? that.data.page : (that.data.page + 1),
          loaded: arr.length < 10 ? true : false,
          show: true
        })
      } else {
        a.alert(t.msg);
      }
    },true)
  },
  click:function(e){
    var that = this,
      i = a.pdata(e).index;
      that.setData({
        hidden: i != that.data.hidden?i:-1
      })
  },
  select: function (e) {
    var that = this,
      i = a.pdata(e).status;
    that.setData({
      page: 1,
      list: [],
      loaded: false,
      status: i
    })
    this.getlist()
  },

  /**
    * 下拉刷新
    */
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded: false
    })
    this.getlist()
    wx.stopPullDownRefresh();
  },
  /**
   *上拉加载
   */
  onReachBottom: function () {
    console.log('加载更多')
    this.data.loaded || this.getlist()
  },
});